/*
 * Copyright (c) 2006 - 2022, webrx.cn All rights reserved.
 *
 */
package cn;

import java.util.Arrays;

/**
 * <p>Project: app2022 - Ex1
 * <p>Powered by webrx On 2022-01-13 09:12:05
 *
* @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Ex1 {
    public static void main(String[] args) {
        String[] ls = new String[]{"age", "eat", "tea", "tan", "ate", "nat", "bat", "book", "bkoo"};
        System.out.println(Arrays.toString(ls));

        long t1 = System.currentTimeMillis();
        for (int n = 0; n < ls.length; n++) {
            String t = ls[n];
            if ("-".equals(t)) {continue;}
            for (int i = n + 1; i < ls.length; i++) {
                if (isOk(t, ls[i])) {
                    ls[n] += "-" + ls[i];
                    ls[i] = "";
                }
            }
        }

        System.out.println(Arrays.deepToString(ls));

        String ok = "";
        for (String t : ls) {
            if ("".equals(t) || "-".equals(t)) {
                continue;
            }
            ok += "," + t;
        }
        String[] oo = ok.substring(1).split(",");
        System.out.println(Arrays.toString(oo));
        StringBuilder su = new StringBuilder("[");
        for(String s : oo){
            String[] t = s.split("-");
            su.append(Arrays.toString(t)+",");
        }
        su.replace(su.lastIndexOf(","),su.lastIndexOf(",")+1,"]");
        System.out.println(su);

        long t2 = System.currentTimeMillis();

        System.out.println(t2-t1 );

    }

    public static boolean isOk(String s1,String s2){
        boolean f = false;
        if(s1.length()==s2.length()){
            char[] a1 = s1.toCharArray();
           Arrays.sort(a1);
            char[] a2 = s2.toCharArray();
            Arrays.sort(a2);
            f = new String(a1).equals(new String(a2)) ? true : false;
        }
        return f;
    }


    public static void t1(String[] args) {
        int[] n1 = {1,2,3};
        int[][] n2 = {{11,22,33},{100,200,300,400}};
        System.out.println(n1);
        System.out.println(n2);
        System.out.println(Arrays.toString(n1));
        System.out.println(Arrays.toString(n2));
        System.out.println(Arrays.deepToString(n2));
    }
}
